<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    import="util.Translator"
    import="java.util.ArrayList"
    import="app.Propiedad"%>

<% //Language management
	Translator t = new Translator();
	String lang = request.getParameter("lang");
	Cookie c = null;

	Cookie [] cookies = request.getCookies();
	if (cookies != null)
		for (Cookie i : cookies)
			if (i.getName().equals("vlang")) {
				c = i;
				break;
			}
	
	if (c == null)
		c = new Cookie("vlang", "en");
			
   if (lang != null) {
	   t.setLanguage(lang);
	   c.setValue(lang);
	}
	else
		t.setLanguage(c.getValue());
 
   response.addCookie(c);

   ArrayList<Propiedad> listaProps = (ArrayList<Propiedad>) request.getAttribute("listaProps");
   String h = request.getParameter ("header");
   int ind = (request.getParameter("ind") != null) ? Integer.parseInt(request.getParameter("ind")) : 0;
   
   /*
   listaProps = new ArrayList<Propiedad>();
   
   for (int i=0; i<10; i++) {
   	listaProps.add(new Propiedad());
   	listaProps.get(i).setTipo(1);
   }
   */
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
   <head>
      <link rel="stylesheet" type="text/css" href="css/regStyle.css">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title><%=t.translate("Buscando en Vencom")%></title>
   </head>
   <body>
      <table class=<%=((h != null) && (h != "0")) ? "mainTable" : "wtheader"%>>
         <% if ((h != null) && (h != "0")) { %>
         <tr>
            <td>
	           	<a href="home.jsp">
	           		<img width="100px" height="50px" src="img/logo.jpg"/>
	           	</a>
            </td>
         </tr>

         <tr> <td><hr color="#ffa200" width="100%" size="3px"/></td> </tr>
         <% } %>
         
         <% if (listaProps == null) { %>
         <tr>
            <td><%=t.translate("Error en la conexion con la base de datos")%>.</td>
         </tr>
         <tr>
            <td><%=t.translate("Por favor, intentelo de nuevo mas tarde")%>.</td>
         </tr>         
         <% } else if (listaProps.size () == 0) { %>
         <tr>
            <td><%=t.translate("Sin resultados")%></td>
         </tr>
         <% } else { %>
         <tr>
            <td>
               <table width="100%">
               	<tr>
               		<td width="40%"><img width="250px" src="img/house.gif"/></td>
               		<td>
               			<table class="propTable" align="left">
               				<thead>
               					<tr>
               						<th align="center" style="border-bottom: 2px solid black" 
               						    colspan="2"> <%=t.translate("Caracter&iacute;sticas")%> </th>
               					</tr>
               				</thead>
               				<tr>
               					<td class="propBox"><%=t.translate("Tipo de propiedad")%></td>   
				                  <% switch (listaProps.get(ind).getTipo()) { 
				                     	case 1: out.println ("<td class='propBox'>" + t.translate("Solar") + "</td>"); break;
				                     	case 2: out.println ("<td class='propBox'>" + t.translate("Piso") + "</td>"); break;
				                     	case 3: out.println ("<td class='propBox'>" + t.translate("Casa terrera") + "</td>"); break;
				                     	case 4: out.println ("<td class='propBox'>" + t.translate("Local comercial") + "</td>");
				                  }%>
               				</tr>
               				<tr>
               					<td width="30%" class="propDarkBox"><%=t.translate("Direcci&oacute;n")%></td>
               					<td class="propDarkBox"><%=listaProps.get(ind).getDireccion()%></td>
               				</tr>
               				<tr>
               					<td class="propBox"><%=t.translate("Dimensiones")%></td>
               					<td class="propBox"><%=listaProps.get(ind).getDimension()%></td>
               				</tr>
               				<tr>
               					<td class="propDarkBox"><%=t.translate("Tipo de oferta")%></td>
               					<td class="propDarkBox"><%=listaProps.get(ind).getOferta()%></td>
               				</tr>
               				<tr>
               					<td class="propBox"><%=t.translate("Precio")%></td>
               					<td class="propBox"><%=listaProps.get(ind).getPrecio()%></td>
               				</tr>
               			</table>
               		</td>
               	</tr>
               </table>
         	</td>
         </tr>
         
         <!-- Index -->
         <tr>
         	<td>
         		<table class="index" align="center">
         			<tr>
         				<%if (ind > 0) {%>
         					<td> <a class="indexBox" href="listProperties.jsp?ind=<%=ind-1%>&header=<%=h%>"><%=t.translate("Ant")%></a> </td>
         				<%}%>
         				
         				<%for (int i = ind; i < (ind +5); i++) {
         					if (i >= listaProps.size())
         						break;%>
    							<td> <a class="indexBox" href="listProperties.jsp?ind=<%=i%>&header=<%=h%>"><%=i%></a> </td>     					
         				<%}%>
         				
         				<%if (ind + 5 < listaProps.size()) {%>
         					<td> <a class="indexBox" href="listProperties.jsp?ind=<%=ind+1%>&header=<%=h%>"><%=t.translate("Sig")%></a> </td>
         				<%}%>
         			</tr>
         		</table>
         	</td>
         </tr>
         <% } %>         
      </table>
   </body>
</html>